package com.tanhua.manager.listener;

import com.tanhua.autoconfig.templates.HuaWeiUGCTemplate;
import com.tanhua.domain.mongo.Movement;
import com.tanhua.dubbo.api.mongo.MovementApi;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(consumerGroup = "movementCheckGroup",topic = "movement_huawei_check")
public class MovementCheckListener implements RocketMQListener<String> {


    @Reference
    private MovementApi movementApi;

    @Autowired
    private HuaWeiUGCTemplate huaWeiUGCTemplate;

    @Override
    public void onMessage(String movementId) {
//        根据movementId查询动态
        Movement movement = movementApi.queryMovementById(movementId);
        if(movement.getState()!=0){  //保证这个动态是需要审核的
            return;
        }

//                审核内容
        boolean textCheck = huaWeiUGCTemplate.textContentCheck(movement.getTextContent());
//                审核图片
        boolean imageCheck = huaWeiUGCTemplate.imageContentCheck(movement.getMedias().toArray(new String[]{}));

        Integer state = 1;
 //        两个都审核通过过在吧state=1  否则state=2
        if(textCheck&&imageCheck){

        }else{
            state = 2;
        }
//        update movement_detail set state=? where id=?
        movementApi.updateStateById(movementId,state);

        System.out.println("执行了检测动态的方法。。。。。。。。。。。。。。");

    }
}
